package com.qdlc.p2p.biz.service.impl;

import org.springframework.stereotype.Service;

import com.qdlc.p2p.biz.service.AbstractPayService;
import com.qdlc.p2p.common.constant.NotifyUrl;
import com.qdlc.p2p.common.constant.TradeCode;
import com.qdlc.p2p.common.util.BeanCopierUtils;
import com.qdlc.p2p.dal.dto.TppTradeLog;

@Service
public class CashFeePayServiceImpl extends AbstractPayService {

	private static final String CALLBACK_URL = WEB_URL + NotifyUrl.CASH_FEE_NOTIFY_PAY_URL + ".html";
	
	private final static String BUSINESS_NAME = "提现手续费代付-";
	
    /** 代收交易Log */
    private ThreadLocal<TppTradeLog> collectTppTradeLogLocal = new ThreadLocal<TppTradeLog>();
    
	@Override
	public String getCallBackUrl() {
		return CALLBACK_URL;
	}

	@Override
	public String getBusinessName() {
		return BUSINESS_NAME;
	}

	@Override
	public TppTradeLog getTppTradeLog() {
		TppTradeLog tppTradeLog = new TppTradeLog();
        BeanCopierUtils.copyProperties(collectTppTradeLogLocal.get(), tppTradeLog);
        tppTradeLog.setId(0l);
        tppTradeLog.setAssociateOrderId(tppTradeLog.getOrderNo());  // 代收订单
        tppTradeLog.setTradeType(TradeCode.C2008.toString());
        return tppTradeLog;
	}

	@Override
	public void analyzePars(Object... pars) {
		if (pars.length != 1) {
            throw new IllegalArgumentException("参数个数不正确!");
        }
        try {
            TppTradeLog collectTppTradeLog = (TppTradeLog) pars[0]; // 代收交易Log
            if (collectTppTradeLog == null) {
                throw new IllegalArgumentException("参数类型不正确!");
            }
            collectTppTradeLogLocal.set(collectTppTradeLog);
        } catch (Exception ex) {
            throw new IllegalArgumentException("参数类型不正确!");
        }
	}

	@Override
	public void tradeFinish(TppTradeLog tppTradeLog, String depositStatus, double tradeAmount) {
		super.tradeFinishForStatus(tppTradeLog, depositStatus, tradeAmount);
	}

	@Override
	public void tradeSuccess(TppTradeLog tppTradeLog, String depositStatus) {
		super.tradeSuccessForStatus(tppTradeLog, depositStatus);
	}

	@Override
	public void tradeFail(TppTradeLog tppTradeLog, String depositStatus) {
		super.tradeFailForStatus(tppTradeLog, depositStatus);
	}

}
